﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using BitAuto.EP.CRMLogSystem.Utils;

namespace BitAuto.EP.CRMLogSystem.Entity
{
    [Serializable]
    public class LogTableInfo
    {
        public string ConnectionString { get; set; }
        public string LogTableId { get; set; }
        public string TableName { get; set; }
        public List<LogFieldInfo> Fileds { get; set; }
        private DataTable dt = null;
        public DataTable Table {
            get {
                if (dt == null)
                    dt = this.CreateTable();
                return dt;
            }
        }
        /// <summary>
        /// 文件路径
        /// </summary>
        public string FilePath { get; set; }
        /// <summary>
        /// 创建表
        /// </summary>
        private DataTable CreateTable()
        {
            dt = new DataTable();
            dt.TableName = this.TableName;
            foreach (var item in this.Fileds)
            {
                dt.Columns.Add(new DataColumn(item.FieldName, SqlCsharpTypeHelper.SqlTypeString2CsharpType(item.FieldType)));
            }
            return dt;
        }
        public void Clear()
        {
            if (this.dt != null)
                dt.Clear();
            this.FilePath = string.Empty;
        }
    }
}
